package com.llgz.hotelmanageapi.controller;


import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.llgz.hotelmanageapi.common.CommonResult;
import com.llgz.hotelmanageapi.pojo.DO.Floor;
import com.llgz.hotelmanageapi.pojo.DO.RoomType;
import com.llgz.hotelmanageapi.pojo.DTO.RoomTypeDTO;
import com.llgz.hotelmanageapi.service.impl.RoomTypeServiceImpl;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiModelProperty;
import io.swagger.annotations.ApiOperation;
import org.apache.commons.lang3.StringUtils;
import org.apache.shiro.authz.annotation.Logical;
import org.apache.shiro.authz.annotation.RequiresRoles;
import org.springframework.beans.BeanUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * <p>
 * 客房类型信息 前端控制器
 * </p>
 *
 * @author Bernie_fang
 * @since 2021-07-19
 */
@RestController
@RequestMapping("/roomType")
@Api(tags = "房型信息接口")
@RequiresRoles(value = {"root", "admin", "manager"}, logical = Logical.OR)
public class RoomTypeController {

    @Autowired
    private RoomTypeServiceImpl roomTypeService;

    @PostMapping("addRoomType")
    @ApiOperation(value = "添加房型信息",response = CommonResult.class,httpMethod = "POST")
    public CommonResult addRoomType(@RequestBody RoomType roomType) {
        roomTypeService.save(roomType);
        return CommonResult.successResponse(null);
    }

    @PostMapping("updateRoomType")
    @ApiOperation(value = "修改房型信息",response = CommonResult.class,httpMethod = "POST")
    public CommonResult updateRoomType(@RequestBody RoomType roomType) {
        roomTypeService.updateById(roomType);
        return CommonResult.successResponse(null);
    }

    @PostMapping("delRoomType")
    @ApiOperation(value = "删除房型信息",response = CommonResult.class,httpMethod = "POST")
    public CommonResult delRoomType(@RequestBody List<String> id) {
        roomTypeService.removeByIds(id);
        return CommonResult.successResponse(null);
    }

    @PostMapping("/queryRoomType")
    @ApiOperation(value = "查询全部房型信息",response = CommonResult.class,httpMethod = "POST")
    public CommonResult queryRoomType(@RequestParam int pageNum, @RequestParam int pageSize, @RequestParam(required = false) String type) {
        QueryWrapper<RoomType> roomTypeQueryWrapper = new QueryWrapper<>();
        roomTypeQueryWrapper.orderByAsc("id");
        roomTypeQueryWrapper.like(!StringUtils.isEmpty(type),"type",type);
        IPage<RoomType> roomTypePage = roomTypeService.page(new Page<>(pageNum, pageSize), roomTypeQueryWrapper);
        return CommonResult.successResponse(roomTypePage);
    }



    @PostMapping("/selectRoomTypeById")
    @ApiOperation(value = "通过ID查询房间信息",response = CommonResult.class,httpMethod = "POST")
    public CommonResult selectRoomTypeById(@RequestParam String id){
        RoomType roomType = roomTypeService.getOne(new QueryWrapper<RoomType>().eq("id",id));
        return CommonResult.successResponse(roomType);
    }

    @PostMapping("/queryAllRoomType")
    @ApiOperation(value = "查询所有房间类型",response = CommonResult.class,httpMethod = "POST")
    public CommonResult queryAllRoomType(){
        QueryWrapper<RoomType> wrapper = new QueryWrapper<>();
        wrapper.select("id","type");
        List<RoomType> list = roomTypeService.list(wrapper);
        return CommonResult.successResponse(list);
    }
//    @GetMapping("/getRoomTypeList")
//    @ApiOperation(value = "查询全部房型信息",response = CommonResult.class,httpMethod = "GET")
//    public CommonResult getRoomTypeList() {
//        QueryWrapper<RoomType> roomTypeQueryWrapper = new QueryWrapper<>();
//        roomTypeQueryWrapper.orderByAsc("id");
//        List<RoomType> list = roomTypeService.list(roomTypeQueryWrapper);
//        return CommonResult.successResponse(list);
//    }
}

